class Account { private int accno,balance; private static double irate=10.25; public void interest(int n) { double si=balance*irate*n/100; System.out.println("Interest is "+si); } public static void setIRate(double r) { irate=r; } public static void showIRate() { System.out.println("irate is "+irate); } public Account(int an,int bl) { accno=an; balance=bl; } } class demo { public static void main(String args[]) { Account.showIRate(); Account a=new Account(4117,25000); Account b=new Account(3012,10000); a.interest(5); b.interest(2); Account.setIRate(9.75); Account.showIRate(); a.interest( 5 ) ; b.interest( 2 ) ; } }
Irate is 10.25 Interest is 12812.5 Interest is 2050.0 Irate is 9.75 Interest is 12187.5 Interest is 1950.0
class Student { private int rollno; private String name; private static int count; public void showData() { System.out.print("RollNo is "+rollno); System.out.println("Name is "+name) ; } public static void showCount() { System.out.println("Total Studs "+count); } public Student(int r,String n) { rollno=r; name=n; count=count + 1; } } class demo { public static void main(String args[]) { Student.showCount(); Student a=new Student(4117,"Amit Jain"); Student b=new Student(3012,"Seeta Rathi"); Student.showCount(); Student c=new Student(5123,"Raja Rao"); Student.showCount( ) ; a.showData(); b.showData(); c.showData(); } }
Total Students: 0 Total Students: 2 Total Students: 3 RollNo is 4117 Name is Amit Jain RollNo is 3012 Name is Seeta Rathi RollNo is 5123 Name is Raja Rao
class MyLib { public static int sum(int n) { int s=0; for(int i=1;i<=n;i++) s=s+i; return s; } public static int factorial(int n) { int m=1; for(int i=1;i<=n;i++) m=m*i; return m; } } class demo { public static void main(String args[]) { int z1=MyLib.sum(10); System.out.println("sum is "+z1); int z2=MyLib.factorial(5); System.out.println("Factorial is "+z2); } }
Sum is 55 Factorial is 120